/*
 * crash_protocol_packet.h
 *
 *  Created on: 07.07.2013
 *      Author: SpirTanol
 */

#ifndef CRASH_PROTOCOL_PACKET_H_
#define CRASH_PROTOCOL_PACKET_H_

#include "packets/data_packet.h"
#include "global.h"

struct CrashData
{
	int oCode;
	uint oTime;

	double oCur[3];
	uint oVol[3];
};

class CrashProtocolPacket : public DataPacket
{
	enum Reg
	{
		R_CODE,
		R_TIME,

		R_CUR = R_TIME + 2,
		R_VOL = R_CUR + 3,

		R_SIZE = R_VOL + 3,
	};

	ushort oData[R_SIZE * 10];

	int oCurScale;

public:
	CrashProtocolPacket(int curScale) { init(curScale); }
	CrashProtocolPacket(const CrashProtocolPacket *packet);
	~CrashProtocolPacket() {}

	CrashData crash(int idx) const;

	inline CrashProtocolPacket *clone() const { return new CrashProtocolPacket(this); }

	inline int curScale() const { return oCurScale; }

private:
	inline void init(int curScale) { addPart(Part(oData, R_SIZE * 10, 50)); oCurScale = curScale; }

};

#endif /* CRASH_PROTOCOL_PACKET_H_ */
